<?php
/**
 * 项目：红河移动电路资源管理信息系统
 *
 * 公司：红河移动分公司
 *
 * @author 李朝应
 *
 * E-mail:lichaoying.hh@163.com
 *
 */
class Org3_model extends CI_Model {
    function __construct()
    {
        parent::__construct();
    }


   function setOrg3($org2_id,$name,$fzr,$email,$tel){
    $data = array(
               'org3_name' => $name,
               'org3_fzr' => $fzr,
               'org3_email' => $email,
               'org3_tel' => $tel,
               'org2_id' => $org2_id
            );

    $this->db->insert('org3', $data);
    return $this->db->affected_rows() ;

   }
 function updateOrg3($id,$org2_id,$name,$fzr,$email,$tel){
    $data = array(
               'org3_name' => $name,
               'org3_fzr' => $fzr,
               'org3_email' => $email,
               'org3_tel' => $tel,
               'org2_id' => $org2_id
            );
      $this->db->where('org3_id',$id);
      $this->db->update('org3', $data);
    return $this->db->affected_rows() ;
 }
function delOrg3($id){
    $this->db->delete('org3', array('org3_id' => $id));
	return true;
 }

function getCount(){
      return  $this->db->count_all("org3");
   }

 function getOrg3All(){
       $sql="SELECT * FROM crms_org3, crms_org2 WHERE crms_org3.org2_id = crms_org2.org2_id";
       $query = $this->db->query($sql);
		if ($query->num_rows() > 0)
		{
			  return $query; //返回查询结果
        }
      }
 function getOrg3By($name){
     $sql="SELECT * FROM crms_org3, crms_org2 WHERE crms_org3.org2_id = crms_org2.org2_id AND crms_org3.org3_name like'%$name%'";
     $query = $this->db->query($sql);
     //SELECT * FROM (`crms_org3`) WHERE `org3_name` LIKE '%1%'
		if ($query->num_rows() > 0)
		{
			  return $query; //返回查询结果
        }
 }
 function getOrg3($id){
     $this->db->where("org3_id", $id);
     $query = $this->db->get('org3');
		if ($query->num_rows() > 0)
		{
			 return $query->row_array(); //返回查询结果
        }
   }
   function hasOrg3($org2_id,$name){
        $this->db->where("org2_id", $org2_id);
        $this->db->where("org3_name", $name);
		$query = $this->db->get('org3');
		if ($query->num_rows() > 0)
		{
			return TRUE;
		}else{
           	return FALSE;
        }
   }
   function hasSameRec($id,$org2_id,$name){
        $this->db->where('org3_id !=', $id);
        $this->db->where("org2_id", $org2_id);
        $this->db->where("org3_name", $name);
		$query = $this->db->get('org3');
        //SELECT * FROM (`crms_org3`) WHERE `org3_id` != '1' AND `org2_id` = '4' AND `org3_name` = '传输组'
		if ($query->num_rows() > 0)
		{
			return TRUE;
		}else{
           	return FALSE;
        }
   }
   function getOrg3In($org2_id){
        $this->db->select("org3_id as id ,org3_name as name");
        $this->db->where("org2_id", $org2_id);
		$query = $this->db->get('org3');
         $oPt=" <option value='NULL' selected='selected'>[-请选择任一项-]</option>";
        foreach ($query->result_array() as $row) {
         $oPt .= "<option value=" .$row['id'].">".$row['name']."</option>";
         }
        return  $oPt;
   }
     function getOrg3In2($org2_id){
        $this->db->select("org3_id as id ,org3_name as name,org3_tel as tel,org3_fzr as fzr");
        $this->db->where("org2_id", $org2_id);
		$query = $this->db->get('org3');
         $oPt="";
        foreach ($query->result_array() as $row) {
         $oPt .= "<option value=" .$row['name']."，|".$row['fzr'].":".$row['tel']."，>".$row['name']."</option>";
         }
        return  $oPt;
   }
}//类定义结束
?>
